<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>WEB安全配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
        label.required:after {
        	  content:'*';
        	  color:red;
        }   
        .delbtn{
            position: relative;
            display: inline-block;
            background: #FFB800;
            border: 1px solid #FFB800;
            border-radius: 2px;
            padding: 4px 12px;
            overflow: hidden;
            color: #FFFFFF;
            text-decoration: none;
            text-indent: 0;
            line-height: 27px;
            width:92px;
        }             
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            帮助文档及注意事项”：1. <a href="#" target="_blank">web安全功能说明</a> 2. <a href="https://wiki-dev.pc.com.cn/pages/viewpage.action?pageId=59219411" target="_blank">web安全配置</a>
            <a class="layui-btn" style="float:right" href="javascript:location.replace(location.href);" title="刷新">
              <i class="layui-icon">&#xe669;</i></a>
        </blockquote>
        <form class="layui-form layui-form-pane"  action="" lay-filter="UpdateInfo">

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend><div id="appNameTitle"></div>全局配置项</legend>
            </fieldset>           
            <input type="hidden" name="id" readonly="true" value="" class="layui-input" disabled>
            <input type="hidden" name="appname" readonly="true" value="" class="layui-input" disabled>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">防火墙状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="waf_enable" value="record"  lay-filter="WafEnable" title="只记录不拦截" checked="">
                        <input type="radio" name="waf_enable" value="on" lay-filter="WafEnable" title="开启">
                        <input type="radio" name="waf_enable" value="off" lay-filter="WafEnable" title="关闭">                                                                            
                    </div>  
            </div> 
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">恶意Ip拦截</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="risk_ip_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
            </div>  

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">内网请求<i class="layui-icon layui-icon-about intranet-marks" style="color: #1E9FFF;"></i></label>
                <div class="layui-input-block">
                    <!--
                    <input type="radio" name="exclude_intranet" value="off" lay-filter="configType" title="拦截分析" checked="">
                    <input type="radio" name="exclude_intranet" value="on" lay-filter="configType" title="忽略">  
                    -->   
                    <input type="checkbox" name="waf_exclude_intranet" lay-skin="switch" lay-filter="switchTest" lay-text="排除|不排除">                                                 
                </div>
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">静态文件<i class="layui-icon layui-icon-about static-marks" style="color: #1E9FFF;"></i></label>
                <div class="layui-input-block">
                    <!--
                    <input type="radio" name="exclude_static" value="off" lay-filter="configType" title="拦截分析" checked="">
                    <input type="radio" name="exclude_static" value="on" lay-filter="configType" title="忽略">     
                    -->     
                    <input type="checkbox" name="waf_exclude_static" lay-skin="switch" lay-filter="switchTest" lay-text="排除|不排除">                                              
                </div>                 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">修改时间</label>
                <div class="layui-input-block">
                  <input type="input" name="updatetime" readonly="true" value="" class="layui-input" disabled>
                </div> 
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>黑白名单配置项</legend>
            </fieldset>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">IP白名单</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="white_ip_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                  
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="whiteIpBtn" style="width:150px" type="button">ip白名单管理</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">URL白名单</label>
                <div class="layui-input-inline"> 
                    <input type="checkbox" name="white_url_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="whiteUrlBtn" style="width:150px" type="button">url白名单管理</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">UA白名单</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="white_ua_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="whiteUaBtn" style="width:150px" type="button">UA白名单管理</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">RF白名单</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="white_rf_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="whiteRfBtn" style="width:150px" type="button">Referer白名单管理</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">IP黑名单</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="black_ip_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="blackIpBtnV2" style="width:150px" type="button">ip黑名单管理</button>
                </div> 
                <!--
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="blackIpBtn" style="width:150px" type="button">ip黑名单管理</button>
                </div> 
                <div class="layui-form-mid layui-word-aux">注:两个ip黑名单实现机制不同,前者适合少量IP,支持正则。后则可以支持百万+ip,可批量添加</div>
                -->
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">URL黑名单</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="waf_urldeny_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="urlDenyBtn" style="width:150px" type="button">URL黑名单管理</button>
                </div> 
                <div class="layui-input-inline">  
                    <div class="layui-form-mid layui-word-aux">注:针对URL来设置黑名单</div>
                </div> 
            </div>

            <!--
            <div class="layui-collapse" lay-filter="test">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">黑白名单规则管理</h2>
                    <div class="layui-colla-content">
                          <table class="layui-table" style="width:80%" id="currentTableId" lay-filter="currentTableFilter"></table>                   
                    </div>
                </div>
            </div>   
            --> 
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>防火墙功能配置项</legend>
            </fieldset>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">URI合法性</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="url_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="UrlBtn" style="width:150px" type="button">url规则配置</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">URL参数</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="url_args_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="ArgsBtn" style="width:150px" type="button">url参数规则配置</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">UserAgent</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="user_agent_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="UaBtn" style="width:150px" type="button">UserAgent规则配置</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">Referer</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="referer_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="RfBtn" style="width:150px" type="button">Referer规则配置</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">Cookie</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="cookie_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="CookieBtn" style="width:150px" type="button">Cookie规则配置</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">post分析</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="post_check" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline" style="width:150px">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="PostBtn" style="width:150px" type="button">Post规则配置</button>
                </div> 
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

  function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    };
    return null;
  };

  function randomString(e) {  
    e = e || 16;
    var t = "abcdefghijkmnpqrstuvwxyz23456789",
    a = t.length,
    n = "lb_";
    for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
    return n
  }

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table;
            $ = layui.$;

var htmls = getQueryString("appname");
$('#appNameTitle').html(htmls);

//修改各个check状态
  form.on('switch(switchTest)', function(data){
    //layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
    //  offset: '6px'
    //});
    //console.log(this.checked);
    //console.log(this.name);
    //console.log(this.value);
    var bodystr = {"name":this.name,"value":this.checked};
    //console.log(JSON.stringify(bodystr))
			$.ajax({
			   url: "/xwaf/config/v1/EditWafConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
         type: "post",
         data: JSON.stringify(bodystr),
         dataType: "json",
			   success: function (resp) {
					  if (resp.code == 0 ) {
              layer.msg('更改成功', {icon: 1});
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });
        //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
  });

//防火墙状态改变
  form.on('radio(WafEnable)', function(data){
    //console.log(this.name);
    //console.log(this.value);
    var bodystr = {"name":this.name,"value":data.value};
			$.ajax({
			   url: "/xwaf/config/v1/EditWafConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
         type: "post",
         data: JSON.stringify(bodystr),
         dataType: "json",
			   success: function (resp) {
					  if (resp.code == 0 ) {
              layer.msg('更改成功', {icon: 1});
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });
  });

      //防火墙output状态
  form.on('radio(wafModel)', function(data){
    if(data.value == 'html'){
        $("#wafModelhtmlTpl").show();
        $("#wafModelUrlTpl").hide();
        $("#wafModelTimeTpl").hide();
    }else if(data.value == 'url'){
        $("#wafModelhtmlTpl").hide();
        $("#wafModelUrlTpl").show();
        $("#wafModelTimeTpl").hide();
    }else{
        $("#wafModelhtmlTpl").hide();
        $("#wafModelUrlTpl").hide();
        $("#wafModelTimeTpl").show();        
    }
      //var bodystr = {"name":this.name,"value":data.value};
			//$.ajax({
			//   url: "/xwaf/config/v1/EditWafConfig" + location.search,
			//   type: "GET",
			//   headers:{'X-Requested-With':'XMLHttpRequest'},
      //   type: "post",
      //   data: JSON.stringify(bodystr),
      //   dataType: "json",
			//   success: function (resp) {
			//		  if (resp.code == 0 ) {
      //        layer.msg('更改成功', {icon: 1});
      //      }else{
      //        layer.msg(resp.msg,{icon:2});
      //      }
			//	  }
		  //  });
  });

        $('#whiteUrlBtn').on("click",function(){
                layer.open({
                    title: 'url白名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=whiteurl',
                });
        });
        $('#whiteIpBtn').on("click",function(){
                layer.open({
                    title: 'ip白名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=whiteip',
                });
        });
        $('#blackIpBtn').on("click",function(){
                layer.open({
                    title: 'ip黑名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=blackip'
                    //content: '/page/xwaf/waf_blackip.html'+ location.search,
                });
        });
        $('#blackIpBtnV2').on("click",function(){
                layer.open({
                    title: '增强型ip黑名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_blackip.html'+ location.search,
                });
        });                 
        $('#whiteUaBtn').on("click",function(){
                layer.open({
                    title: 'UA白名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=whiteua',
                });
        });
        $('#whiteRfBtn').on("click",function(){
                layer.open({
                    title: 'Referer白名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=whiterf',
                });
        });
        $('#urlDenyBtn').on("click",function(){
                layer.open({
                    title: 'URL黑名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_urldeny_list.html'+ location.search,
                });
        });
        $('#UrlBtn').on("click",function(){
                layer.open({
                    title: 'URL规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=url',
                });
        });
        $('#ArgsBtn').on("click",function(){
                layer.open({
                    title: 'URL参数规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=args',
                });
        });
        $('#UaBtn').on("click",function(){
                layer.open({
                    title: 'UserAgent规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=useragent',
                });
        });
        $('#RfBtn').on("click",function(){
                layer.open({
                    title: 'referer规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=referer',
                });
        });
        $('#CookieBtn').on("click",function(){
                layer.open({
                    title: 'Cookie规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=cookie',
                });
        });
        $('#PostBtn').on("click",function(){
                layer.open({
                    title: 'Post规则配置',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/waf_rule.html'+ location.search+'&ruletype=post',
                });
        });

$(".static-marks").mouseover(function() {
    layer.tips('静态文件忽略不做任何操作,直接放行!', this, {
      tips: [1, "#000"],
      time:3000
    });
});

$(".intranet-marks").mouseover(function() {
    layer.tips('从内网IP过来的请求不做任何操作,直接放行!', this, {
      tips: [1, "#000"],
      time:3000
    });
});


			$.ajax({
			   url: "/xwaf/config/v1/GetWafConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
			   success: function (resp) {
          
					if (resp.id > 0 ) {
      				  form.val('UpdateInfo', {
                  "id": resp.id
                  ,"appname": resp.appname
                  ,"waf_enable": resp.waf_enable
                  ,"waf_exclude_intranet": resp.waf_exclude_intranet
                  ,"waf_exclude_static": resp.waf_exclude_static
                  ,"white_url_check": resp.white_url_check
                  ,"white_ip_check": resp.white_ip_check
                  ,"white_ua_check": resp.white_ua_check
                  ,"white_rf_check": resp.white_rf_check
                  ,"black_ip_check": resp.black_ip_check
                  ,"url_check": resp.url_check
                  ,"url_args_check": resp.url_args_check
                  ,"user_agent_check": resp.user_agent_check
                  ,"referer_check": resp.referer_check
                  ,"cookie_check": resp.cookie_check
                  ,"post_check": resp.post_check    
                  ,"risk_ip_check": resp.risk_ip_check  
                  ,"waf_urldeny_check": resp.waf_urldeny_check 
                  //,"waf_model": resp.waf_model        
                  //,"waf_html": resp.waf_html        
                  //,"waf_redirect_url": resp.waf_redirect_url    
                  //,"waf_expire_time": resp.waf_expire_time
                  //,"waf_url_length": resp.waf_url_length
                  ,"updatetime": resp.updatetime                              
      				  }) 

                if(resp.waf_model == 'html'){
                  $("#wafModelhtmlTpl").show();
                  $("#wafModelUrlTpl").hide();
                  $("#wafModelTimeTpl").hide();
                }else if (resp.waf_model == 'url'){
                  $("#wafModelhtmlTpl").hide();
                  $("#wafModelUrlTpl").show();
                  $("#wafModelTimeTpl").hide();
                }else{
                  $("#wafModelhtmlTpl").hide();
                  $("#wafModelUrlTpl").hide();
                  $("#wafModelTimeTpl").show();        
                }                     
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });	

    form.verify({
        waf_url_length: [
          /^\d+\/\d+$/
          ,"格式不对,eg:100/60!"
        ]
    });

        //监听提交
        /*
        form.on('submit(saveBtn)', function(datas){		
            var re = /^\d+$/;
            if (re.test(datas.field.waf_url_length)){
                console.log("ok");
            } else {
                layer.msg("url长度必须为大于等于0的整数!",{icon:2});
                return false;
            }
            if (re.test(datas.field.waf_expire_time)){
                console.log("ok");
            } else {
                layer.msg("禁止时长必须为大于0的整数!",{icon:2});
                return false;
            }
    		    console.log(JSON.stringify(datas.field)); 
            layer.confirm('确定修改?', {icon: 3, title:'提示',yes: function(index){
                         $.ajax({
                           url: "/xwaf/config/v1/UpdateWafModel"+location.search,
                           type: "POST",
                           data: JSON.stringify(datas.field),
                           dataType: "json",
                           success: function (resp) {
    					                console.log(resp);
                               if(resp.code == 0){
                                   layer.msg('修改成功', {
                                              icon: 1,
                                              time: 2000
                                            },function(){
                                                window.location.reload();
                                    });  
                               }else{
                                   layer.msg('修改失败',{icon:2});
                               }
                            }
                         });		  	  
                   },
                    cancel: function(index, layero){ 
                        layer.close(index);
                    } 
            }); 	                       	   
    	      return false; 	
    		});
        */
    });
    function delTpl(id) {
      //console.log(id);
      var TplIndex = id;
      TplIndex--;
      $("#tpl-"+id).remove();
    }
    
</script>
</body>
</html>